Add multiline logging interceptor sample for Datadog compatibility #249
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add multiline logging interceptor sample for Datadog compatibility
Summary
Adds a new sample demonstrating how to format multiline exception logs as single-line JSON within Temporal SDK boundaries. This solves the issue where multiline tracebacks span multiple log entries in log aggregation systems like Datadog, making them difficult to parse and analyze.
The solution implements a surgical interceptor that:
message,type, andtracebackfieldsThe implementation follows the established interceptor pattern from the sentry sample.
Review & Testing Checklist for Human
temporal server start-dev) and verify multiline exceptions are logged as single-line JSON in worker outputworkflow.unsafe.sandbox_unrestricted()usage in the workflow interceptor is appropriate and follows Temporal best practicesNotes
Testing limitations: The implementation wasn't fully tested in a live Temporal environment due to temporal CLI not being available in the development environment. The core JSON formatting logic was validated, but full interceptor integration testing is needed.
Performance impact: The interceptor adds JSON serialization overhead on every exception, but this should be minimal since exceptions are rare in normal operation.
Requested by: @deepika-awasthi
Link to Devin run: https://app.devin.ai/sessions/37122594b322437b8e42cef51d4104d1